package com.freight.base.dao;

import com.freight.base.entity.City;
import com.freight.base.vo.CityListVo;
import com.freight.base.vo.CityVo;
import com.freight.core.base.FreightBaseDao;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * 城市维表数据处理层
 *
 * @author huyingtai
 */
public interface CityDao extends FreightBaseDao<City, Long> {

    @Query(value = "select new com.freight.base.vo.CityVo(city.cityCode ,city.cityName " +
            ",province.provinceCode ,province.provinceName,province.lat,province.lng)" +
            "from City city " +
            "left join Province province on city.provinceCode = province.provinceCode " +
            "where city.cityCode =?1 ")
    CityVo getCityVoLevel(@Param("cityCode") String cityCode);


    @Query(value = "select new com.freight.base.vo.CityVo(city.cityCode,city.cityName,province.provinceCode" +
            ",province.provinceName,province.lat,province.lng)" +
            "from City city " +
            "left join Province province on city.provinceCode = province.provinceCode " +
            "where city.cityCode in (:cityCodes) ")
    List<CityVo> getCityVoLevel(@Param("cityCodes") List<String> cityCodes);

    @Query(value = "select new com.freight.base.vo.CityListVo(city.cityCode,city.cityName,city.lng,city.lat) from City city " +
            "where city.provinceCode = :code ")
    List<CityListVo> getCityList(@Param("code") String code);

}